package com.css.zfzx.fwsjcj.modules.taskmanage.personfootprint.service.Impl;

import com.css.bpm.platform.utils.PlatformSessionUtils;
import com.css.bpm.platform.utils.UUIDGenerator;
import com.css.zfzx.fwsjcj.modules.taskmanage.personfootprint.entity.FwPersonFootprintEntity;
import com.css.zfzx.fwsjcj.modules.taskmanage.personfootprint.repository.FootPrintRepository;
import com.css.zfzx.fwsjcj.modules.taskmanage.personfootprint.service.FootPrintService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

@Service
public class FootPrintServiceImpl implements FootPrintService {
    @Autowired
    FootPrintRepository footPrintRepository;
    @Override
    public void saveFootPrint(FwPersonFootprintEntity fwPersonFootprintEntity) {
        fwPersonFootprintEntity.setFootId(UUIDGenerator.getUUID());
        fwPersonFootprintEntity.setCreatTime(new Date());
        //fwPersonFootprintEntity.setUserId(PlatformSessionUtils.getUserId());
        footPrintRepository.save(fwPersonFootprintEntity);
    }

    @Override
    public List<FwPersonFootprintEntity> findAllFoot(HttpServletRequest request) {
        List<FwPersonFootprintEntity> all = footPrintRepository.findAll();
        return all;
    }

    @Override
    public List<FwPersonFootprintEntity> findByTaskIdAndUserId(String userId,String taskId) {
        List<FwPersonFootprintEntity> allByUserIdAndTaskId = footPrintRepository.findAllByUserIdAndTaskIdOrderByCreatTime(taskId, userId);
        return allByUserIdAndTaskId;
    }

    @Override
    public List<FwPersonFootprintEntity> findByTaskIdAndUserIdAndTime(String userId,String taskId,String start,String end ) {
        List<FwPersonFootprintEntity> allByUserIdAndTaskIdAndTime = footPrintRepository.findAllByUserIdAndTaskIdAndTimeOrderByCreatTime(taskId, userId,start,end);
        return allByUserIdAndTaskIdAndTime;
    }
}
